package com.myk.game.gobangchess.constants;

/**
 * 消息处理器，客户端和服务器通用同一个
 */
public class Msger {

    //服务端推送消息
    public static final String updateVersion = "updateVersion"; //更新客户端版本
    public static final String broadcast = "broadcast"; //广播通知3秒
    public static final String showInfoDialog = "showInfoDialog"; //通知用户显示文本信息弹窗，非阻塞。
    public static final String otherLogin = "otherLogin"; //其他玩家登录，附带登录玩家的昵称
    public static final String otherLogout = "otherLogout"; //其他玩家下线，附带下线玩家昵称
    public static final String refreshPlayerInfo = "refreshPlayerInfo"; //更新玩家自己的信息
    public static final String refreshPlayerListSum = "refreshPlayerListSum"; //更新在线玩家的数量
    public static final String refreshRoomList = "refreshRoomList"; //更新大厅房间列表，附带房间名称，和房间里的人数信息
    public static final String refreshRoomInfo = "refreshRoomInfo"; //更新房间信息，房间名字玩家和观众之类的
    public static final String refreshGameInfo = "refreshGameInfo"; //更新棋盘信息，当前步数和棋子分布
    public static final String refreshCountdown = "refreshCountdown"; //更新倒计时信息
    public static final String youCanMove = "youCanMove"; //通知你可以行棋
    public static final String youNotMove = "youNotMove"; //通知你不可以行棋
    public static final String dispatchCustomBottom = "dispatchCustomBottom"; //服务端分派自定义按钮
    public static final String dispatchAskInputDialog = "dispatchAskInputDialog"; //服务端向用户询问，通知客户端打开自定义文本输入弹窗 (askId&title&topTip&midTip&bottomTip&isForceInput&limitReg)
    public static final String gameStart = "gameStart"; //通知游戏开始，谁和谁在哪个房间开始游戏
    public static final String winMessage = "winMessage"; //通知获胜信息
    public static final String pushNotificationIds = "pushNotificationIds"; //推送公告列表（仅仅只是列表id，客户端取没看过的id再像服务端请求具体类容）
    public static final String pushNotificationText = "pushNotificationText"; //根据客户端的请求，推送具体的公告内容（包含id和文本）
    public static final String refreshUserInfo = "refreshUserInfo"; //推送个人资料
    public static final String pushChatMessage = "pushChatMessage";// 推送房间内聊天消息 （{msgId}&{nickName}&{msg}）其中msgId是连续的int可用于判断两个消息之间是否有消息没有收到，msgId始终在 000-999之间循环.
    public static final String refreshDefMessageList = "refreshDefMessageList"; //通知用户显示预设消息文本列表（{msg};{msg}）

    //客户端请求操作
    public static final String keepLive = "keepLive"; //维持存活的请求，服务端不进行任何操作
    public static final String requestLogin = "requestLogin"; //用户请求登录，附带信息 idCode@version
    public static final String requestRegister = "requestRegister"; //用户请求登录，附带信息 idCode&nickName&contact&version
    public static final String requestLogout = "requestLogout"; //用户请求退出
    public static final String requestEnterRoom = "requestEnterRoom"; //用户请求进入房间
    public static final String requestLeaveRoom = "requestLeaveRoom"; //用户离开房间
    public static final String requestBeChessPlayer = "requestBeChessPlayer"; //申请成为下棋者，附带信息 1：黑方  2：白方
    public static final String requestLeaveSeat = "requestLeaveSeat"; //申请离开座位
    public static final String requestMoveLater = "requestMoveLater"; //请求落子
    public static final String requestAdmitDefeat = "requestAdmitDefeat"; //请求认输
    public static final String requestChessRule = "requestChessRule"; //请求详细棋规则
    public static final String requestChessStatistics = "requestChessStatistics"; //请求棋的数据统计
    public static final String requestCustomBottomEvent = "requestCustomBottomEvent"; //发送动态自定义按钮事件
    public static final String requestCacheSignContent = "requestCacheSignContent"; //客户端请求获取缓存标记具体内容
    public static final String requestNotifications = "requestNotifications"; //告诉服务端自己有哪些公告还没看过，传入公告id列表
    public static final String requestUserInfo = "requestUserInfo"; //客户端请求获取个人资料

    public static final String requestUserAmountFlow = "requestUserAmountFlow"; //客户端请求获取个人代币流水
    public static final String requestUserPlayingDetail = "requestUserPlayingDetail"; //客户端请求个人对弈统计
    public static final String requestLoginPlayerList = "requestLoginPlayerList"; //客户端请求获取登录玩家列表
    public static final String requestOtherPlayerInfo = "requestOtherPlayerInfo"; //客户端请求查看他人信息
    public static final String requestPlayerRankList = "requestRankPlayerList";//客户端请求名人堂信息
    public static final String requestRoomRankList = "requestRoomRankList";//客户端请求热棋榜信息
    public static final String requestPokePlayer = "requestPokePlayer"; //请求戳一戳，传入1:黑方昵称，3:黑方倒计时，2:白方昵称，4:白方倒计时
    public static final String requestDefMessageList = "requestDefMessageList"; //请求获取预设消息列表
    public static final String requestSendDefMessage = "requestSendDefMessage"; //请求发送预设消息，传入预设消息序号
    public static final String requestSendCustomMessage = "requestSendCustomMessage"; //请求发送自定义文本消息
    public static final String requestAnswerAskInputInfo = "requestAnswerAskInputInfo"; //向服务端发送自定义输入的文本，传入askId&inputText


    //服务端返回结果
    public static final String connSuccess = "connSuccess"; //网络连接成功
    public static final String loginSuccess = "loginSuccess"; //登录成功, 附带登陆者的昵称
    public static final String loginFailed = "loginFailed"; //登录失败，附带失败原因
    public static final String registerSuccess = "registerSuccess"; //注册成功，附带idCode&提示信息
    public static final String registerFailed = "registerFailed"; //注册失败，附带失败原因
    public static final String enterRoomSuccess = "enterRoomSuccess"; //进入房间成功
    public static final String enterRoomFailed = "enterRoomFailed"; //进入房间失败，附带失败原因
    public static final String beChessPlayerSuccess = "beChessPlayerSuccess"; //成为下棋者成功
    public static final String beChessPlayerFailed = "beChessPlayerFailed"; //成为下棋者失败。附带失败原因
    public static final String returnCacheSignContent = "returnCacheSignContent"; //服务端返回缓存标记具体内容

    //服务端管理员推送消息
    public static final String refreshAccountList = "refreshAccountList"; //刷新账号列表
    public static final String managerRefreshRoomList = "managerRefreshRoomList"; //管理员更新房间列表
    public static final String refreshChessList = "refreshChessList"; //展示可玩的棋类的列表
    public static final String refreshAccountDetail = "refreshAccountDetail"; //展示账号详情
    public static final String refreshAmountDetail = "refreshAmountDetail"; //展示资产明细
    public static final String refreshPlayingDetail = "refreshPlayingDetail"; //展示对弈记录
    public static final String refreshChatAdjustDetail = "refreshChatAdjustDetail"; //展示聊天权限管理详情
    public static final String refreshTodayRecords = "refreshTodayRecords"; //展示某房间今日战报
    public static final String refreshRoomConfigInfo = "refreshRoomConfigInfo"; //展示某房间的配置信息
    public static final String refreshTodayLogin = "refreshTodayLogin"; //展示今日登录用户
    public static final String refreshSystemInfo = "refreshSystemInfo"; //展示当前系统信息
    public static final String refreshActiveNotifications = "refreshActiveNotifications"; //刷新活跃公告列表
    public static final String refreshOldNotificationIds = "refreshOldNotificationIds";//刷新已关闭过时公告id列表
    public static final String refreshOldNotificationDetails = "refreshOldNotificationDetails"; //展示已关闭过时公告的内容详情

    //管理员客户端请求操作
    public static final String requestManagerLogin = "requestManagerLogin"; //管理员请求登陆
    public static final String requestManagerLogout = "requestManagerLogout"; //管理员请求退出
    public static final String requestAccountList = "requestAccountList";//管理员请求账号列表数据
    public static final String requestSearchBanAccountList = "requestSearchBanAccountList"; //管理员请求筛选封禁的账号列表数据
    public static final String requestSearchCheckAccountList = "requestSearchCheckAccountList"; //管理员请求筛选审核的账号列表数据
    public static final String requestSearchLikeNameAccountList = "requestSearchLikeNameAccountList"; //管理员请求模糊搜索昵称账号列表数据
    public static final String requestAccountDetail = "requestAccountDetail"; //管理员请求查看用户账号详情
    public static final String requestAmountDetail = "requestAmountDetail"; //管理员请求查看用户资产明细
    public static final String requestPlayingDetail = "requestPlayingDetail"; //管理员请求查看用户对弈记录
    public static final String requestChatAdjustDetail = "requestChatAdjustDetail"; //管理员请求查看用户聊天权限情况
    public static final String requestAddAccount = "requestAddAccount"; //管理员添加账号
    public static final String requestRoomList = "requestRoomList";//管理员请求房间列表数据
    public static final String requestChessList = "requestChessList";//管理员请求可玩的棋的列表
    public static final String requestCreateRoom = "requestCreateRoom";//管理员请求创建房间
    public static final String requestCloneRoom = "requestCloneRoom";//管理员请求克隆增加房间
    public static final String requestCloseRoom = "requestCloseRoom";//管理员请求关闭房间
    public static final String requestCleanRoom = "requestCleanRoom"; //管理员请求清理房间
    public static final String requestTodayRecords = "requestTodayRecords"; //管理员请求房间今日战报
    public static final String requestDaysRecords = "requestDaysRecords"; //管理员请求房间多日战报
    public static final String requestRoomConfigInfo = "requestRoomConfigInfo"; //管理员请求查看某个房间的配置详情
    public static final String requestTodayLogin = "requestTodayLogin"; //管理员请求查看今日登录用户
    public static final String requestSystemInfo = "requestSystemInfo"; //管理员请求查看系统资源信息
    public static final String requestGroupNotice = "requestGroupNotice"; //管理员请求给所有在线用户发一个消息
    public static final String requestAddNotification = "requestAddNotification"; //管理员创建一封公告
    public static final String requestCloseNotification = "requestCloseNotification"; //管理员关闭一封公告
    public static final String requestActiveNotifications = "requestActiveNotifications";//管理员获取所有活跃的公告列表，包含id和内容
    public static final String requestOldNotificationIds = "requestOldNotificationIds";//获取过时的公告id列表
    public static final String requestOldNotificationDetail = "requestOldNotificationDetail"; //根据id获取过时的公告内容
    public static final String requestPassAccount = "requestPassAccount"; //管理员审核通过账号
    public static final String requestRejectAccount = "requestRejectAccount"; //管理员审核拒绝账号
    public static final String requestChangeAmount = "requestChangeAmount"; //管理员申请增加或者减少逆界代币额度
    public static final String requestChangeBadge = "requestChangeBadge"; //管理员申请修改荣誉标签
    public static final String requestChangeContact = "requestChangeContact"; //管理员申请修改联系方式
    public static final String requestAdjustChatLevel = "requestAdjustChatLevel"; //管理员申请调整聊天权限

    //管理员服务端返回结果
    public static final String managerLoginSuccess = "managerLoginSuccess"; //管理员登录成功
    public static final String managerLoginFailed = "managerLoginFailed"; //管理员登录失败
    public static final String managerAddAccountFailed = "managerAddAccountFailed"; //管理员添加账号失败
    public static final String managerAddAccountSuccess = "managerAddAccountSuccess"; //管理员添加账号成功


    /**
     * 获取消息值，如果格式不对，或者类型不对，返回null
     */
    public static String getValueByType(String msg, String type) {
        String[] m = msg.split("=",2);
        if (m.length != 2) {
            return null;
        }
        else if (m[0].isEmpty()) {
            return null;
        }
        else if (m[1].isEmpty()) {
            return null;
        }
        else if (!m[0].equals(type)) {
            return null;
        }
        else {
            return m[1];
        }
    }

    /**
     * 获取消息类型,如果无法获取返回 ""
     */
    public static String getMsgType(String msg) {
        String[] m = msg.split("=",2);
        if (m.length != 2) {
            return "";
        }
        return m[0];
    }

    /**
     * 获取消息的值,如果无法获取返回 ""
     */
    public static String getMsgValue(String msg) {
        String[] m = msg.split("=",2);
        if (m.length != 2) {
            return "";
        }
        return m[1];
    }

    /**
     * 检查消息格式是否正确
     */
    public static boolean checkMsg(String msg) {
        String[] m = msg.split("=",2);
        if (m.length != 2) {
            return false;
        }
        else if (m[0].isEmpty()) {
            return false;
        }
        else if (m[1].isEmpty()) {
            return false;
        }
        else {
            return true;
        }
    }

    /**
     * 创建正确格式的消息
     *
     * @param type  消息类型，从Msger的常量中获取
     * @param value 消息的值
     * @return
     */
    public static String createMsg(String type, String value) {
        String msg = type + "=" + value;
        return msg;
    }

//    public static void main(String[] args) {
//        System.out.println(getMsgType("3232=aaaa"));
//        System.out.println(getMsgValue("3232=aaaa"));
//    }
}
